/*
	   _           _      _           _     _ 
	  (_)         | |    | |         (_)   | |
	   _ _   _ ___| |_ __| |_ __ ___  _  __| |
	  | | | | / __| __/ _` | '__/ _ \| |/ _` |
	  | | |_| \__ \ || (_| | | | (_) | | (_| |
	  | |\__,_|___/\__\__,_|_|  \___/|_|\__,_|
	 _/ |                                     
	|__/ 
	
	Copyright 2013 Caspar Isemer and and Eva Krueger, http://justdroid.org
	
	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at
	
		http://www.apache.org/licenses/LICENSE-2.0
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License. 
*/

package org.justdroid.justdroid;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.provider.CallLog;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.format.Time;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.LinearLayout;
import android.widget.TextView;

@SuppressLint("DefaultLocale")
public class StatusApp extends JustDroidActivity {
	private Handler handler;
	private View viewBeforeDataConnection, viewBeforeAlarm, viewBeforeLocation, viewBeforeUnreadEmails, viewBeforeBluetooth;
	@SuppressWarnings("unused")
	private TextView txtStatusBattery, txtStatusSignal, txtStatusDataConnection, txtStatusMissedCalls, txtStatusUnreadTextMessages, 
	txtStatusUnreadEmails, txtStatusNextAlarm, txtStatusTimeDate, txtStatusLocation, txtStatusBluetooth, txtStatusBrightness;
	private LocationManager locManager;
	private  BroadcastReceiver mReceiver;
	int currentSignalStrength = 0;
	int asu = 0;
	
	/** Function to attach onTouchListener and onFocusListener to the buttons **/
	void attachListener(TextView textView) {
		final String text = textView.getText().toString();
		/*textView.setOnTouchListener(new OnTouchListener() {
			
			@Override
			public boolean onTouch(View view, MotionEvent arg1) {
				giveFeedback(text);
				return false;
			}
		});*/
		textView.setOnFocusChangeListener(new OnFocusChangeListener() {
			
			@Override
			public void onFocusChange(View view, boolean hasFocus) {
				if(hasFocus) {
					giveFeedback(text);
				}
			}
		});
	}
	
	/** Function to announce the text of the view that received focus or on which the onTouch event was triggered**/
	void giveFeedback(String text) {
		//vibrate
		Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
	    vibrator.vibrate(300);
	    //TTS feedback
	    if(!TTS.isSpeaking())
	    	TTS.speak(text);
	}
	
	/** Create the Status activity **/
	@SuppressLint("HandlerLeak")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.status);
		super.onCreate(savedInstanceState);

		/** Find UI elements **/
		txtStatusBattery = (TextView) findViewById(R.id.txtStatusBattery);
	//	txtStatusSignal = (TextView) findViewById(R.id.txtStatusSignal);
		txtStatusDataConnection = (TextView) findViewById(R.id.txtStatusDataConnection);
		txtStatusMissedCalls = (TextView) findViewById(R.id.txtStatusMissedCalls);
		txtStatusUnreadTextMessages = (TextView) findViewById(R.id.txtStatusUnreadTextMessages);
		txtStatusUnreadEmails = (TextView) findViewById(R.id.txtStatusUnreadEmails);
		txtStatusNextAlarm = (TextView) findViewById(R.id.txtStatusNextAlarm);
		txtStatusTimeDate = (TextView) findViewById(R.id.txtStatusTimeDate);
		txtStatusLocation = (TextView) findViewById(R.id.txtStatusLocation);
		//txtWifiStatus = (TextView) findViewById(R.id.txtStatusWifiStatus);
		txtStatusBluetooth = (TextView) findViewById(R.id.txtStatusBluetooth);
		txtStatusBrightness = (TextView) findViewById(R.id.txtStatusBrightness);
		
		viewBeforeDataConnection = findViewById(R.id.viewBeforeDataConnection);
		viewBeforeAlarm = findViewById(R.id.viewBeforeAlarm);
		viewBeforeLocation = findViewById(R.id.viewBeforeLocation);
		viewBeforeBluetooth = findViewById(R.id.viewBeforeBluetooth);
		viewBeforeUnreadEmails = findViewById(R.id.viewBeforeUnreadEmails);
		
		viewBeforeUnreadEmails.setVisibility(View.GONE);
		txtStatusUnreadEmails.setVisibility(View.GONE);
		
		
		handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				//display the battery level
				txtStatusBattery.setText(getResources().getString(R.string.txtStatusBattery) + " " + msg.getData().getString("batteryLevel") + "%");
				txtStatusBattery.setContentDescription(getResources().getString(R.string.txtStatusBattery) + " " + msg.getData().getString("batteryLevel") + "%");
				attachListener(txtStatusBattery);
				//display the number of bars indicating the cell signal strength
				//txtStatusSignal.setText(getResources().getString(R.string.txtStatusSignal) + " " + msg.getData().getString("signalStrength") + " bars");
				//txtStatusSignal.setContentDescription(getResources().getString(R.string.txtStatusSignal) + " " + msg.getData().getString("signalStrength") + " bars");
				//display data connection type
				
				
				if(msg.getData().getString("dataConnection").equals("null")) {
					txtStatusDataConnection.setVisibility(View.GONE);
					viewBeforeDataConnection.setVisibility(View.GONE);
				}
				else {
					txtStatusDataConnection.setVisibility(View.VISIBLE);
					viewBeforeDataConnection.setVisibility(View.VISIBLE);
					txtStatusDataConnection.setText(msg.getData().getString("dataConnection") + " " + getResources().getString(R.string.txtStatusDataConnection));
					txtStatusDataConnection.setContentDescription(msg.getData().getString("dataConnection") + " " + getResources().getString(R.string.txtStatusDataConnection));
					attachListener(txtStatusDataConnection);
				}
				//display number of unread text messages
				txtStatusUnreadTextMessages.setText(msg.getData().getString("unreadText") + " " + getResources().getString(R.string.txtStatusUnreadTextMessages));
				txtStatusUnreadTextMessages.setContentDescription(msg.getData().getString("unreadText") + " " + getResources().getString(R.string.txtStatusUnreadTextMessages));
				attachListener(txtStatusUnreadTextMessages);
				
				
				//display number of unread emails
			//	txtStatusUnreadEmails.setText(msg.getData().getString("unreadMails") + " " + getResources().getString(R.string.txtStatusUnreadEmails));
				//txtStatusUnreadEmails.setContentDescription(msg.getData().getString("unreadMails") + " " + getResources().getString(R.string.txtStatusUnreadEmails));
				//attachListener(txtStatusUnreadEmails);
				
				//display date and time of the next alarm
				if(msg.getData().getString("nextAlarm") != null) {
					viewBeforeAlarm.setVisibility(View.VISIBLE);
					txtStatusNextAlarm.setVisibility(View.VISIBLE);
					txtStatusNextAlarm.setText(getResources().getString(R.string.txtStatusNextAlarm) + " " + msg.getData().getString("nextAlarm"));
					txtStatusNextAlarm.setContentDescription(getResources().getString(R.string.txtStatusNextAlarm) + " " + msg.getData().getString("nextAlarm"));
					attachListener(txtStatusNextAlarm);
				}
				else {
					txtStatusNextAlarm.setVisibility(View.GONE);
					viewBeforeAlarm.setVisibility(View.GONE);
				}
				
				//display current date and time
				/** Update the Time and Date status **/
				Time today = new Time(Time.getCurrentTimezone());
				today.setToNow();
				txtStatusTimeDate.setText(today.format("%k:%M") + " on " + msg.getData().getString("currentTime"));
				txtStatusTimeDate.setContentDescription(today.format("%k:%M") + " on " + msg.getData().getString("currentTime"));
				attachListener(txtStatusTimeDate);

				//display Wi Fi status
			/*	if(msg.getData().getString("wifiOn").equals("null")) {
					txtWifiStatus.setText(getResources().getString(R.string.txtStatusWifiStatusOff));
					txtWifiStatus.setContentDescription(getResources().getString(R.string.txtStatusWifiStatusOff));
				}
				else {
					txtWifiStatus.setText(getResources().getString(R.string.txtStatusWifiStatusOn));
					txtWifiStatus.setContentDescription(getResources().getString(R.string.txtStatusWifiStatusOn));
					attachListener(txtStatusDataConnection);
				}
				*/
				//display the brightness status
				if(msg.getData().getString("brightness").equals("1")) { //automatic
					txtStatusBrightness.setText(getResources().getString(R.string.txtStatusBrightness));
					txtStatusBrightness.setContentDescription(getResources().getString(R.string.txtStatusBrightness));
				}
				else {
					//30, 102, 255
					switch(getBrightnessValue()) {
					case 30:
						txtStatusBrightness.setText(getResources().getString(R.string.txtStatusBrightnessOff));
						txtStatusBrightness.setContentDescription(getResources().getString(R.string.txtStatusBrightnessOff));
						break;
					case 102:
						txtStatusBrightness.setText(getResources().getString(R.string.txtStatusBrightnessMedium));
						txtStatusBrightness.setContentDescription(getResources().getString(R.string.txtStatusBrightnessOff));
						break;
					case 255:
						txtStatusBrightness.setText(getResources().getString(R.string.txtStatusBrightnessBright));
						txtStatusBrightness.setContentDescription(getResources().getString(R.string.txtStatusBrightnessOff));
						break;
					}
				}
				attachListener(txtStatusBrightness);
			}
		};

		// Currently, do not know how to write the code that lists the individual status items with a ListView
		// if that technically is the best option
		// Desired items are in this specific order:
		//Battery level at XX%
		// XX data enabled (only displayed if 3G or WIFI connected; then only say '3G data enabled' or 'WIFI data enabled')
		
		ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
			Runnable periodicTask = new Runnable() {
			    public void run() {
			    	Message msg = new Message();
					Bundle bundle = new Bundle();
					
					//get battery level
					bundle.putString("batteryLevel", getBatteryLevel());
					
					//get signal strength
					//bundle.putString("signalStrength", getSignalStrength());
					
					//check if connected to network
					if(isConnected(getApplicationContext())) {
						if(isWifiConnected(getApplicationContext())) {
							bundle.putString("dataConnection", Utils.WIFI);
						}
						else if(is3gEnabled()) {
							bundle.putString("dataConnection", Utils.THREEG);
						}
						else {
							bundle.putString("dataConnection", Utils.TWOG);
						}
					}
					else {
						bundle.putString("dataConnection", "null");
					}
			/*		
					//check if WiFI is on/off
					if(isWifiOn(getApplicationContext())) {
							bundle.putString("wifiOn", Global.WIFI);
					}
					else {
						bundle.putString("wifiOn", "null");
					}*/
					
					// XX unread text messages
					//check number of unread SMS
					bundle.putString("unreadText", getUnreadText());

					//bundle.putString("unreadMails", getAllUnreadMails());
					
					// Next alarm at XX:XX, Day_of_Week
					bundle.putString("nextAlarm", getNextAlarm());
					
					// XX:XX on Month XX, 2013 (Time and date: specifically in this order as time keeps changing whereas date is the same for 24h)
					bundle.putString("currentTime", getCurrentDateAndTime());
					
					//get brightness mode and status
				    if(getBrightnessMode() == 0) { //manual
				    	bundle.putString("brightness", "0");
				    }
				    else {
				    	bundle.putString("brightness", "1");
				    }
				   
				    
					msg.setData(bundle);
					handler.sendMessage(msg);
			    }
			};
		//These tasks are performed every 10 seconds
		executor.scheduleAtFixedRate(periodicTask, 0, 5, TimeUnit.SECONDS);

		// Cell signal at XX bars
		// XX unread eMails
		
		// Location data enabled (only displayed if location info is enabled)
		if(isGPSenabled()) {
			txtStatusLocation.setText(getResources().getString(R.string.txtStatusLocation));
			txtStatusLocation.setContentDescription(getResources().getString(R.string.txtStatusLocation));
		}
		else {
			viewBeforeLocation.setVisibility(View.GONE);
        	txtStatusLocation.setVisibility(View.GONE);
		}
		attachListener(txtStatusLocation);
		
		//listen for change in GPS status
		locManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

	    // Define a listener that responds to location updates
	    LocationListener locationListener = new LocationListener() {
	        
			@Override
			public void onLocationChanged(Location arg0) {
			}

			@Override
			public void onProviderDisabled(String s) {
				 if(LocationManager.GPS_PROVIDER.equals(s)) {
				viewBeforeLocation.setVisibility(View.GONE);
            	txtStatusLocation.setVisibility(View.GONE);
				 }
			}

			@Override
			public void onProviderEnabled(String s) {
				if(LocationManager.GPS_PROVIDER.equals(s)) {
				viewBeforeLocation.setVisibility(View.VISIBLE);
				txtStatusLocation.setVisibility(View.VISIBLE);
            	txtStatusLocation.setText(getResources().getString(R.string.txtStatusLocation));
            	txtStatusLocation.setContentDescription(getResources().getString(R.string.txtStatusLocation));
            	attachListener(txtStatusLocation);
				}
			}

			@Override
			public void onStatusChanged(String provider, int status, Bundle extras) {
				viewBeforeLocation.setVisibility(View.VISIBLE);
            	txtStatusLocation.setText(getResources().getString(R.string.txtStatusLocation));
            	txtStatusLocation.setContentDescription(getResources().getString(R.string.txtStatusLocation));
				attachListener(txtStatusLocation);
			}
	    };
	    // Register the listener with the Location Manager to receive location updates
	    locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
		
	    if(isBluetoothEnabled()) {
	    	txtStatusBluetooth.setContentDescription(getResources().getString(R.string.txtStatusBluetooth));
	    	attachListener(txtStatusBluetooth);
	    }
	    else {
	    	viewBeforeBluetooth.setVisibility(View.GONE);
	    	txtStatusBluetooth.setVisibility(View.GONE);
	    }
		/** Put most everything before here **/
		
		
		//telManager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
	//	telManager.listen(new SignalStrengthListener(), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
	
	    	mReceiver = new BroadcastReceiver() {
	        @Override
	        public void onReceive(Context context, Intent intent) {
	            final String action = intent.getAction();

	            if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
	                final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
	                                                     BluetoothAdapter.ERROR);
	                switch (state) {
	                case BluetoothAdapter.STATE_OFF:
	                	viewBeforeBluetooth.setVisibility(View.GONE);
	        	    	txtStatusBluetooth.setVisibility(View.GONE);
	                    break;
	                case BluetoothAdapter.STATE_ON:
	                	viewBeforeBluetooth.setVisibility(View.VISIBLE);
	        	    	txtStatusBluetooth.setVisibility(View.VISIBLE);
	                    break;
	                }
	            }
	        }
	    };
	    // Register for broadcasts on BluetoothAdapter state change
	    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
	    this.registerReceiver(mReceiver, filter);
	}
	
	@Override
	public void onResume() {
		super.onResume();
		// XX missed calls
		txtStatusMissedCalls.setText(getMissedCallCount() + " " + getResources().getString(R.string.txtStatusMissedCalls));
		txtStatusMissedCalls.setContentDescription(getMissedCallCount() + " " + getResources().getString(R.string.txtStatusMissedCalls));
		attachListener(txtStatusMissedCalls);
		//TTS.speak(getResources().getString(R.string.status));
		
		//get the root layout
		LinearLayout layout = (LinearLayout) findViewById(R.id.status);
		Utils.applyFontColorChanges(getApplicationContext(), layout);  Utils.applyFontSizeChanges(getApplicationContext(), layout);  Utils.applyFontTypeChanges(getApplicationContext(), layout);
	}
	
	@Override
	public void onDestroy() {
		super.onDestroy();
		this.unregisterReceiver(mReceiver);
	}
	
	@SuppressLint("DefaultLocale")
	private String getBatteryLevel() {
		IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
		Intent batteryStatus = getApplicationContext().registerReceiver(null, ifilter);
		int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
		int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
		float perct = (level / (float)scale)*100;
		return String.format("%.0f", perct);
	}
	
	private boolean isWifiConnected(Context context) {
		ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = cm.getActiveNetworkInfo();
		return (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI);
	}
	/*
	private boolean isWifiOn(Context context) {
		WifiManager wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
		return wifi.isWifiEnabled();
	}*/
	
	private boolean isConnected(Context context){
		ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = cm.getActiveNetworkInfo();
	    return (info != null && info.isConnected());
	}
	
	private boolean is3gEnabled() {
		if(((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE)).getNetworkType() >= TelephonyManager.NETWORK_TYPE_UMTS)
		    return true;
		return false;
	}
	
	private String getMissedCallCount() {
		String[] projection = { CallLog.Calls.CACHED_NAME, CallLog.Calls.CACHED_NUMBER_LABEL, CallLog.Calls.TYPE };
	    String where = CallLog.Calls.TYPE+"="+CallLog.Calls.MISSED_TYPE;          
	    Cursor cursor = this.getContentResolver().query(CallLog.Calls.CONTENT_URI, projection, where, null, null);
	    cursor.moveToFirst();    
	    return Integer.toString(cursor.getCount());
	}
	
	private String getUnreadText() {
		final Uri SMS_INBOX = Uri.parse("content://sms/inbox");
		Cursor cursor = getContentResolver().query(SMS_INBOX, null, "read = 0", null, null);
		return Integer.toString(cursor.getCount());
	}
	
	private String getNextAlarm() {
		String nextAlarm = (android.provider.Settings.System.getString(getContentResolver(),
			    Settings.System.NEXT_ALARM_FORMATTED));
		if(nextAlarm.equals(""))
			return null;
		String time = nextAlarm.substring(nextAlarm.indexOf(" "));
		String day = nextAlarm.substring(0, nextAlarm.indexOf(" "));
		
		if(day.startsWith("Sun")) {
			day = "Sunday";
		}
		else if(day.startsWith("Mon")) {
			day = "Monday";
		}
		else if(day.startsWith("Tue")) {
			day = "Tuesday";
		}
		else if(day.startsWith("Wed")) {
			day = "Wednesday";
		}
		else if(day.startsWith("Thu")) {
			day = "Thursday";
		}
		else if(day.startsWith("Fri")) {
			day = "Friday";
		}
		else {
			day = "Saturday";
		}
		nextAlarm = time + ", " + day.toString();
		return nextAlarm;
	}
	
	@SuppressLint("SimpleDateFormat")
	private String getCurrentDateAndTime() {
		Time today = new Time(Time.getCurrentTimezone());
		today.setToNow();
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat sdf  = new SimpleDateFormat("MMMM dd, yyyy");
		String dateresult = sdf.format(cal.getTime());
		return dateresult;
	}
	
	private boolean isGPSenabled() {
		final LocationManager manager = (LocationManager)getApplicationContext().getSystemService (Context.LOCATION_SERVICE );
		boolean gpsStatus = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
		return gpsStatus;
	}
	
	private boolean isBluetoothEnabled() {
		BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
		if (bluetoothAdapter == null) {
		    return false;
		} else {
		    if (!bluetoothAdapter.isEnabled()) {
		        return false;
		    }
		}
		return true;
	}
	
	private int getBrightnessMode() {
		int curBrightnessMode = 0;
		try {
		    curBrightnessMode = android.provider.Settings.System.getInt(
		    getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE);
		} catch (Exception e) {
		    e.printStackTrace();
		}
		return curBrightnessMode;
	}
	
	private int getBrightnessValue() {
		int curBrightnessValue = 0;
		try {
		    curBrightnessValue = android.provider.Settings.System.getInt(
		    getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS);
		} catch (Exception e) {
		    e.printStackTrace();
		}
		return curBrightnessValue;
	}
	
	/*private String getSignalStrength() {
		try {
		    final TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
		    if(tm.getAllCellInfo() == null)
		    	Log.e("this","null");
		    //tm.getCellLocation()
		    for (final CellInfo info : tm.getAllCellInfo()) {
		        if (info instanceof CellInfoGsm) {
		            final CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();
		            Log.e("this",Integer.toString(gsm.getLevel()));
		            // do what you need
		        } else if (info instanceof CellInfoCdma) {
		            final CellSignalStrengthCdma cdma = ((CellInfoCdma) info).getCellSignalStrength();
		            Log.e("this",Integer.toString(cdma.getLevel()));
		            // do what you need
		        } else if (info instanceof CellInfoLte) {
		            final CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();
		            Log.e("this",Integer.toString(lte.getLevel()));
		            // do what you need
		        } else {
		            throw new Exception("Unknown type of cell signal!");
		        }
		    }
		} catch (Exception e) {
		    Log.e("this", "Unable to obtain cell signal information", e);
		}
		return null;
	}
	*/
	
	/*private class SignalStrengthListener extends PhoneStateListener{

    @Override
    public void onSignalStrengthsChanged(SignalStrength signalStrength)
        {
            super.onSignalStrengthsChanged(signalStrength);
            if (telManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA)
                currentSignalStrength = signalStrength.getCdmaDbm();                  
            else
                asu = signalStrength.getGsmSignalStrength();
            
            Log.e("tjos",Integer.toString(asu));
        }
    }*/
	
	/*	private String getAllUnreadMails() {
		Account[] accounts = AccountManager.get(this).getAccountsByType("com.google");
		int count = 0;
		for (Account account : accounts) {
			count += getUnreadMailsByAccount(account.name);
		}
		return Integer.toString(count);
	}*/
	
	public static final class LabelColumns {
	    public static final String NAME = "name";
	    public static final String NUM_UNREAD_CONVERSATIONS = "numUnreadConversations";
	}
	/*
	private int getUnreadMailsByAccount(String account) {
		int unread = 0;
		//Uri LABELS_URI = Uri.parse("content://gmail-ls/labels/");
	    //Uri ACCOUNT_URI = Uri.withAppendedPath(LABELS_URI, account);
	    //ContentResolver contentResolver = getContentResolver();
	    Cursor cursor = getContentResolver().query(GmailContract.Labels.getLabelsUri(account), null, null, null, null);
	    //Cursor cursor = contentResolver.query(ACCOUNT_URI, null, null, null, null);

	    if(cursor != null) {
	    	
	    //iterate over all labels in the account
		    if (cursor.moveToFirst()) {
		        int unreadColumn = cursor.getColumnIndex(LabelColumns.NUM_UNREAD_CONVERSATIONS);
		        int nameColumn = cursor.getColumnIndex(LabelColumns.NAME);
		        do {
		            String name = cursor.getString(nameColumn);
			        if(name.equals(GmailContract.Labels.LabelCanonicalNames.CANONICAL_NAME_INBOX)) {
			        	unread += Integer.valueOf(cursor.getString(unreadColumn));
			        }
		        } while (cursor.moveToNext());
		    }
	    }
	    return unread;
	}*/
}